#include "tileboarditems.h"
#include "gamedialogmanager.h"
#include <QPainter>
#include <QStyleOption>
#include "gameboardorganizer.h"
#include "gametable.h"
/*


  VillageTile class

  */

VillageTile::VillageTile(GameBoardOrganizer *board, int x, int y)
    :GameBoardItem(board), _x(x), _y(y)
{
    _haunted = false;
    setAcceptHoverEvents(true);
}

QRectF VillageTile::boundingRect() const{

    int totalWidth = 3*WIDTH;
    return QRectF(-totalWidth/2+_x*WIDTH, -totalWidth/2+_y*WIDTH, WIDTH, WIDTH);
}

void VillageTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    bool down = option->state & QStyle::State_Sunken;
    bool over = option->state & QStyle::State_MouseOver;
    if(down){
        painter->fillRect(boundingRect(), Qt::white);
    }else if(over){
        painter->fillRect(boundingRect(), Qt::black);
    }else{
        painter->fillRect(boundingRect(), *c);
    }
    if(_haunted)
    {
        painter->fillRect( -WIDTH*3/2+_x*WIDTH, -WIDTH*3/2+_y*WIDTH, 10, 10, Qt::red );
        painter->drawRect( -WIDTH*3/2+_x*WIDTH, -WIDTH*3/2+_y*WIDTH, 10, 10 );
    }
    painter->drawRect( boundingRect() );
}

void VillageTile::mousePressEvent(QGraphicsSceneMouseEvent *event){
    /*
    GhostSlot* temp = getParentBoard()->getGameTable()->getGhostBoards().at(0)->getSlots().at(1);
    getDialogManager()->askBattleDialog(temp);
    update();
    */
    /* TAO REQUEST DIALOG TEST
    GSColor c = getDialogManager()->askTaoDialog();
    switch(c){
    case RED:
        qDebug("red");
        break;
    default:
        break;
    }
    */
    emit clicked(this);
}

void VillageTile::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    update();
}

void VillageTile::setHaunted(bool b){
    _haunted = b;
    update();
}

/*


  TEA SHOP CLASS


*/

TeashopTile::TeashopTile(GameBoardOrganizer* board, int x, int y):
    VillageTile(board,x, y)
{
    c = new QColor(qrand()%255, qrand()%255, qrand()%255, 255);
}

/*


  SORCERER SHOP CLASS


*/

SorcererTile::SorcererTile(GameBoardOrganizer* board, int x, int y):
    VillageTile(board,x, y)
{
    c = new QColor(qrand()%255, qrand()%255, qrand()%255, 255);
}


/*


  ALTAR SHOP CLASS



  */


AltarTile::AltarTile(GameBoardOrganizer* board, int x, int y):
    VillageTile(board,x, y)
{
    c = new QColor(qrand()%255, qrand()%255, qrand()%255, 255);
}

/*


  PAVILION SHOP CLASS



  */


PavilionTile::PavilionTile(GameBoardOrganizer* board, int x, int y):
    VillageTile(board,x, y)
{
    c = new QColor(qrand()%255, qrand()%255, qrand()%255, 255);
}


